import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: YKH
 * Date: 2022-04-30
 * Time: 8:37
 * author:Main
 */
public class Main {
    public static final String [] suit = { "♥","♠","♣","♦"};
    //创建一副牌
    public static List<Card> createCard(List<Card> cardList ) {

        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                Card card = new Card(suit[i],j);
                cardList.add(card);
            }
        }
        System.out.println();
        return cardList;
    }

    //洗牌
    public  static  void shuffle (List<Card> cardList) {

        for (int i = cardList.size()-1; i >0 ; i--) {
            Random random = new Random();
            int index = random.nextInt(i);
            swap( cardList, i, index);
        }
    }
    //发牌 三个人轮流摸牌
    public static List<List<Card>> dealCard ( List<Card> cardList) {
        List<Card>hand1 = new ArrayList<>();
        List<Card>hand2 = new ArrayList<>();
        List<Card>hand3 = new ArrayList<>();
        List<List<Card>> hands = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);

        for( int i = 0; i<5 ;i++) {
            for( int j =0;j<3;j++) {
                Card card = cardList.remove(0);
                hands.get(j).add(card);
            }
        }
        return hands;
    }
    private static void swap( List<Card> cardList , int i,int index) {
        Card temp = cardList.get(i);
        cardList.set(i,cardList.get(index));
        cardList.set(index,temp);
    }
     public static void main(String[] args) {
        List<Card> cardList = new ArrayList<>();
        cardList = createCard(cardList);
         shuffle(cardList);
         System.out.println(cardList);
         List<List<Card>> hands  = dealCard(cardList);

         System.out.println("第1个人的牌:" + hands.get(0));
         System.out.println("第2个人的牌:" + hands.get(1));
         System.out.println("第3个人的牌:" + hands.get(2));

         System.out.println("剩余的牌:" + cardList);


     }
}
